package com.jn.exam.paperSubmit.service.impl;


import com.jn.exam.paperSubmit.entity.vo.Answer;
import com.jn.exam.paperSubmit.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;


/**
 * @author 江南大学1033190417
 * @date 2021/11/27 23:40
 */
@EnableBinding(Source.class)//定义消息的推送管道
public class IMessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output;

    @Override
    public boolean sendAnswer(Answer answer, String studentId, String examId) {
        boolean send = output.send(MessageBuilder.withPayload(answer)
                .setHeader("studentId", studentId)
                .setHeader("examId", examId)
                .build());
        return send;
    }
}
